<?php
include "CouchDb/Couch.php";

$couch = new Couch(array("host" => "localhost", "port" => 5984));

$couch->running() or die("we're offline\n");

$db = $couch->database("test_suite_db");

$doc = $db->newDocument();
$doc->field = "value";
$doc->food = "fries";

$doc->save();



$view = $db->newView();

$view->function = "function(doc) { if(doc.food) return map(doc.id, doc); }";
 
foreach($view->documents() AS $doc) {
	var_dump($doc);
}



$all = $db->view("_all_docs");

foreach($all->documents() AS $document) {
    echo $document->id()."\n";
}
var_dump($document->id());

$document->foo = 1;
$document->save();


$doc = $db->get("FF4F4479CF30923993E32D3025E6BCB5");
var_dump("objectvars");
var_dump(get_object_vars($doc));

$doc->foo=2;

$doc->bar = 123;
$doc->save();

var_dump(get_object_vars($doc));
$doc = $db->get("FF4F4479CF30923993E32D3025E6BCB5");

var_dump(get_object_vars($doc));


$doc2 = $db->newDocument();

$doc2->value="GO!";
$doc2->save();

$all = $db->view("_all_documents");

foreach($all->documents() AS $doc) {
    echo "$doc->name \n";
}




$doc->name = "Damien";
$doc->save();


    

?>